const AboutUsDetailModel = require('../../models/about/about')
const aboutData = require('../../db/about/about')

class AboutUsController {
  async getAboutDetail(ctx) {
    try {
      const count = await AboutUsDetailModel.countDocuments()
      if (count === 0) {
        const result = await AboutUsDetailModel.insertMany(aboutData, {
          ordered: false, // 忽略错误继续插入其他数据
        })

        // console.log(`成功插入 ${result.insertedCount} 条数据`)
      }

      const findAboutUsDetailData = await AboutUsDetailModel.find()
      console.log(findAboutUsDetailData, '00000')
      ctx.status = 200
      ctx.body = {
        success: true,
        data: {
          findAboutUsDetailData,
        },
      }
    } catch (err) {
      ctx.status = 500
      ctx.body = { error: 'Failed to save data', details: err.message }
    }
  }
}

module.exports = new AboutUsController()
